package org.ru.mse10.cvis.web.bean.action;

import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

import org.ru.mse10.cvis.entity.codelists.Codelist;
import org.ru.mse10.cvis.service.CodelistService;
import org.ru.mse10.cvis.web.bean.BaseFormBean;
import org.ru.mse10.cvis.web.helper.LanguageModelTableHelper;

/**
 * The Class SystemDefaultsAction.
 * 
 * @author mse10slb
 */
@SessionScoped
@ManagedBean(name = "systemDefaultsAction")
public class SystemDefaultsAction extends
		BaseFormBean<Codelist, CodelistService> {

	/** The helper. */
	private LanguageModelTableHelper helper = new LanguageModelTableHelper();;

	/** The service. */
	@EJB
	private CodelistService service;

	/** language of the system. */
	private String language;

	/**
	 * Gets the codelist.
	 * 
	 * @param code
	 *            the code
	 * @return the codelist
	 */
	public Codelist getCodelist(String code) {
		return service.retrieveCodelistByCode(code);
	}

	/**
	 * Inits the.
	 * 
	 * @param codelist
	 *            the codelist
	 */
	public void init(Codelist codelist) {
		setTargetEntity(codelist);
		helper.reset(codelist.getCodelistValues());
	}

	/**
	 * Gets the language.
	 * 
	 * @return systems language
	 */
	public String getLanguage() {
		return language;
	}

	/**
	 * sets the language of the system.
	 * 
	 * @param language
	 *            to be set.
	 */
	public void setLanguage(String language) {
		this.language = language;
	}

	/**
	 * System defaults action.
	 * 
	 * @return string for navigation
	 */
	public String systemDefaultsAction() {
		init(service.retrieveCodelistByCode("4"));
		return "systemDefaultsAction";
	}

	/**
	 * Gets the helper.
	 * 
	 * @return the helper
	 */
	public LanguageModelTableHelper getHelper() {
		return helper;
	}

	/**
	 * Sets the helper.
	 * 
	 * @param helper
	 *            the new helper
	 */
	public void setHelper(LanguageModelTableHelper helper) {
		this.helper = helper;
	}
}
